import { http } from '@/utils/http'
import type { Category, editParams, LoginResult, MsgPageData, MainPost } from '@/types/userInfo'
import type { PageParams } from '@/types/common'

/**
 * 获取标签
 */
export const getUserTagType = () => {
  return http<Category[]>({
    method: 'GET',
    url: '/api/aidou/type',
    data: {
      isLoad: false,
    },
  })
}

/**
 * 更新用户标签
 */
export const postUserTagType = (data: string) => {
  return http({
    method: 'POST',
    url: `/api/aidou/add_tags/${data}`,
  })
}

/** 获取用户已选标签 */
export const getUserTag = () => {
  return http<string[]>({
    method: 'GET',
    url: '/api/aidou/tags',
  })
}

/**
 * 修改用户信息
 * @param data 请求参数
 */
export const postUpdateUserInfo = (data: editParams) => {
  return http({
    method: 'POST',
    url: '/api/aidou/edit',
    data,
  })
}

/**
 * 获取用户信息
 * @param data
 */
export const getUserInfo = (data: { id: number }) => {
  return http<LoginResult>({
    method: 'GET',
    url: `/api/user/getUserInfo`,
    data,
  })
}

/** 删除信息 */
export const deleteMessage = (id: number) => {
  return http({
    method: 'GET',
    url: '/api/aidou/message/delete',
    data: { id },
  })
}
/**
 * 获取用户历史信息
 */
export const getUserMsg = (id: number, data: PageParams) => {
  return http<MsgPageData>({
    method: 'POST',
    url: `/api/aidou/get_message/${id}`,
    data,
  })
}
/** 获取用户点赞列表 */
export const getLike = (params: PageParams) => {
  return http<MsgPageData>({
    method: 'POST',
    url: '/api/aidou/get_like',
    data: params,
  })
}

/** 获取用户收藏列表 */
export const getCollect = (params: PageParams) => {
  return http<MsgPageData>({
    method: 'POST',
    url: '/api/aidou/get_collect',
    data: params,
  })
}

/** 获取用户当前未读信息 */
export const getMsgUnreadApi = () => {
  return http<number>({
    method: 'GET',
    url: '/api/aidou/message/unread',
  })
}

/** 点赞 */
export const postLike = (id: number) => {
  return http({
    method: 'GET',
    url: '/api/aidou/like',
    data: { id },
  })
}

/** 取消点赞 */
export const deleteLike = (id: number) => {
  return http({
    method: 'GET',
    url: '/api/aidou/like/cancel',
    data: { id },
  })
}

/** 收藏 */
export const postCollect = (id: number) => {
  return http({
    method: 'GET',
    url: '/api/aidou/collect',
    data: { id },
  })
}

/** 取消收藏 */
export const deleteCollect = (id: number) => {
  return http({
    method: 'GET',
    url: '/api/aidou/collect/cancel',
    data: { id },
  })
}

/** 发布信息 */
export const publishMsg = (params: { content: string; parent_id?: number }) => {
  return http({
    method: 'POST',
    url: '/api/aidou/message/publish',
    data: params,
  })
}

/** 获取主贴信息 */
export const getMainPostApi = (id: number) => {
  return http<MainPost>({
    method: 'GET',
    url: '/api/aidou/message',
    data: { id },
  })
}

/** 获取评论列表 */
export const getComment = (id: number, params: PageParams) => {
  return http<MsgPageData>({
    method: 'POST',
    url: `/api/aidou/message/comment/${id}`,
    data: params,
  })
}

/** 获取未读消息列表 */
export const getUnreadMessage = (params: PageParams) => {
  return http<MsgPageData>({
    method: 'POST',
    url: '/api/aidou/unread_message',
    data: params,
  })
}
